home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / STDLIB.PAK / SEARCH.CPP < prev    next >
Text File  |  1997-05-06  |  1KB  |  43 lines

  1.  #include <algorithm>
  2.  #include <list>
  3.  
  4.  using namespace std;
  5.  
  6.  int main ()
  7.  {
  8.    //
  9.    // Initialize a list sequence and subsequence with characters.
  10.    //
  11.    char seq[40]    = "Here's a string with a substring in it";
  12.    char subseq[10] = "substring";
  13.    list<char> sequence(seq, seq+39);
  14.    list<char> subseqnc(subseq, subseq+9);
  15.    //
  16.    // Print out the original sequence.
  17.    //
  18.    cout << endl << "The subsequence, " << subseq << ", was found at the ";
  19.    cout << endl << "location identified by a '*'" << endl << "     ";
  20.    //
  21.    // Create an iterator to identify the location of
  22.    // subsequence within sequence.
  23.    //
  24.    list<char>::iterator place;
  25.    //
  26.    // Do search.
  27.    //
  28.    place = search(sequence.begin(), sequence.end(),
  29.                   subseqnc.begin(), subseqnc.end());
  30.    //
  31.    // Identify result by marking first character with a '*'.
  32.    //
  33.    *place = '*';
  34.    //
  35.    // Output sequence to display result.
  36.    //
  37.    for (list<char>::iterator i = sequence.begin(); i != sequence.end(); i++)
  38.      cout << *i;
  39.    cout << endl;
  40.  
  41.    return 0;
  42.  }
  43.